#include <windows.h>
#include <stdio.h>

#include <memory_rows.h>
#include <mTestUnit.h>

void T_memory_rows( void * ptr )
{
	mTestCase * TestCase = (mTestCase *) ptr;

	MemoryRows_Init mem[] = 
				{
					{ 30,   16, 0 },
					{ 15,  128, 0 },
					{ 15,  512, 0 },
					{ 15, 1024, 0 },
					{ 10, 4096, 0 },
					{  0,    0, 0 }
				};

	MemoryRows info;
	int i = 0;
	char * buf[50];
	char * buf2;

	if ( memory_rows_init( &info, mem ) != 0 )
	{
		mTestSuiteError( TestCase, "memory_rows_init" ); 
	}

	for ( i = 0; i < sizeof( buf ) / sizeof( buf[0] ); i++ )
	{
		if ( memory_rows_alloc( &info, &buf[i], 16 ) != 0 )
		{
			mTestSuiteError( TestCase, "memory_rows_alloc" ); 
		}
	}

	memory_rows_getstats( &info );

	if ( memory_rows_alloc( &info, &buf2, 1600 ) != 0 )
	{
		mTestSuiteError( TestCase, "memory_rows_alloc 1600" ); 
	}

	memory_rows_getstats( &info );

	if ( memory_rows_free( &info, &buf2 ) != 0 )
	{
		mTestSuiteError( TestCase, "memory_rows_free 1600" ); 
	}

	memory_rows_getstats( &info );

	memory_rows_destroy( &info );
}
